import sys
from django.views.debug import technical_500_response
from django.conf import settings


class UserBasedExceptionMiddleware(object):

    def process_exception(request, exception):
        if request.user.is_superuser or request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
            return technical_500_response(request, *sys.exc_info())